home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Russian / cpsimage.cab / data / xps / xmetWriteImg.proc < prev    next >
Text File  |  2009-03-16  |  3KB  |  101 lines

  1.  
  2. /* @WriteLayer
  3.   // DESCRIPTION
  4.   Write the layer for the image provided. Both the directory and filename
  5.   are given.  If the directory or filename, "fname", are not given
  6.   nothing is done and the call returns.
  7. */
  8.  
  9. private
  10. PROCEDURE
  11. WriteLayer (XIPIMAGE img,
  12.             STRING dir,
  13.             STRING fname,
  14.             INTEGER pgNum,
  15.             INTEGER layerNum,
  16.             INTEGER  isTIFF)
  17. {
  18.   INTEGER ltype = img.getMember (num:layerNum, member:"layerType");
  19.   INTEGER comp  = img.getMember (num:layerNum, member:"compression");
  20.   STRING ext    = "." + mapExt (img: img, layer: layerNum, isTIFF: isTIFF);
  21.   // SetStatus (op: "debug");
  22.  
  23.   if ( ! dir || ! fname )
  24.      return;
  25.   if ( ltype == XIP_JBIG2Dict || ltype == XIP_Text || ltype == XIP_Thumbnail)
  26.      return;
  27.  
  28.   // Write files; waiting until we get ability to write compressed directly
  29.   // Till then we have to uncompress and write, ugly!
  30.  
  31.   XIPIMAGE imgL = img.getLayer (num: layerNum);
  32.  
  33.   if ( ltype == XIP_Contone || comp == XIP_JPEG_COMP) {
  34.  
  35.     // This handles PDF cascaded compression of Jpeg followed with deflate
  36.     if (comp != XIP_JPEG_COMP)
  37.        imgL = imgL.unCompress();
  38.  
  39.     imgL.writejpgop (filename: dir +"/Images/pg"+ pgNum +fname +layerNum +ext);
  40.     }
  41.  
  42.   else if ( ltype == XIP_ColorMask || ltype == XIP_Binary || ltype == XIP_ContoneMask) {
  43.  
  44.     STRING outFile = dir +"/Images/pg"+ pgNum + fname +  layerNum + ext;
  45.  
  46.     if ( ltype == XIP_ColorMask || ltype == XIP_ContoneMask) {
  47.       imgL = imgL.unCompress ();
  48.  
  49.       if ( imgL.getMember (member: "photometry") == XIP_K_COLOR )
  50.         imgL = imgL.invert();
  51.  
  52.       imgL = imgL.modheader (modify: ("Photometry:transparency:0", // png tag
  53.                                       "Encoding:interleave:pixel",
  54.                                       "Photometry:name:grayLinear") );
  55.       }
  56.     else
  57.       imgL = imgL.unCompress();
  58.  
  59.     /* For now set the resolution to 0 in order to prevent XPS viewer using it */
  60.     if ( ext == ".tif" || ext == ".TIF" )
  61.       imgL.writetifop (filename: outFile, ccitt: 4, noicc:TRUE);
  62.     else if ( ext == ".png" || ext == ".PNG" )
  63.       imgL.writepng (filename: outFile);
  64.     else {
  65.       print "WriteLayer: Error, not configured for writing " + ext + " files";
  66.       return;
  67.       }
  68.     }
  69.  
  70.   Execute (); 
  71.   // SetStatus (op: "debug");
  72. }
  73.  
  74.  
  75.  
  76. /* @GetFile
  77.   // DESCRIPTION
  78.   Read an IMS file into XIPIMAGE object and returns it to the caller.
  79.   Assumes the IMS file has an extension of ims on the file name.  If not
  80.   it does a readimage and tries to return that as an XIPIMAGE.
  81. */
  82.  
  83. private
  84. PROCEDURE GetFile (STRING name)
  85.   RETURNS (XIPIMAGE img)
  86. {
  87.   // Object used to manage error infformatormation in a try-catch call
  88.   STATUS status;
  89.   STRING imsName;
  90.   
  91.   // Try to read the input IMS file
  92.   try {
  93.     if ( name.ext() == "ims" || name.ext() == "IMS")
  94.       img = ReadIMS (filename: name).exec();
  95.     else
  96.       img = readimage (filename: name).exec();
  97.   } catch {
  98.     print "Error: " + status.message;
  99.   }
  100. }
  101.